<template>
  <el-form
    ref="ruleFormRef"
    :model="ruleForm"
    :rules="rules"
    label-width="auto"
    class="login-ruleForm"
    size="default"
    status-icon
  >
    <el-form-item label="用户名：" prop="name">
      <el-input v-model="ruleForm.name" placeholder="手机号/用户名" />
    </el-form-item>
    <el-form-item label="密码：" prop="password">
      <el-input v-model="ruleForm.password" placeholder="密码" />
    </el-form-item>
    <el-form-item class="remember-content">
      <el-checkbox v-model="ruleForm.rememberMe">记住密码</el-checkbox>
      <span class="no-password">忘记密码？</span>
    </el-form-item>
    <el-form-item class="tool-content">
      <el-button type="primary" @click="submitForm(ruleFormRef)"
        >登 录</el-button
      >
    </el-form-item>

    <span class="register-btn" @click="onRegister">立即注册</span>
  </el-form>
</template>

<script setup lang='ts'>
import { reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";
import { useLoginStore } from "@/stores/modules/login"; //路径别名，引入store
const { setState } = useLoginStore();

interface IRuleForm {
  name: string;
  password: string;
  rememberMe: boolean;
}

const ruleForm = reactive<IRuleForm>({
  name: "",
  password: "",
  rememberMe: false,
});
const ruleFormRef = ref<FormInstance>();
const rules = reactive<FormRules<IRuleForm>>({
  name: [{ required: true, message: "请输入名字或手机号", trigger: "blur" }],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
});

const submitForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.validate((valid) => {
    if (valid) {
      console.log("submit!");
    } else {
      console.log("error submit!");
      return false;
    }
  });
};
const onRegister = () => {
  setState({ key: "panelType", value: "register" });
};
</script>

<style lang='scss' scoped>
.no-password {
  color: $blcolor;
  cursor: pointer;
}
::v-deep {
  .tool-content {
    .el-form-item__content {
      display: flex;
      justify-content: center;
      .el-button {
        flex: 1;

        height: 40px;
        line-height: 40px;

        border-radius: 10px;
        box-shadow: 0 6px 16px 0 rgb(78 111 242 / 30%);
        font-size: 17px;
        font-weight: 800;
        border: 0;
        color: #fff;
        cursor: pointer;
      }
    }
  }
  .remember-content {
    .el-form-item__content {
      display: flex;
      justify-content: space-between;
    }
  }
}
.register-btn {
  color: $blcolor;
  float: right;
  cursor: pointer;
}
</style>
